package com.qianfeng.zhangwei.extras.eventbus;

import com.qianfeng.zhangwei.extras.BaseApplication;
import com.qianfeng.zhangwei.extras.R;
import com.qianfeng.zhangwei.extras.fragment.BaseFragment;
import com.qianfeng.zhangwei.extras.utils.AppConfig;

import org.androidannotations.annotations.EFragment;
import org.simple.eventbus.EventBus;
import org.simple.eventbus.Subscriber;
import org.simple.eventbus.ThreadMode;

@EFragment(R.layout.fragment_test)
public class TestFragment extends BaseFragment {
    private EventBus eventBus = EventBus.getDefault();


    @Override
    public void inject() {
        eventBus.register(this);
    }

    @Subscriber
    private void test(String title) {
        BaseApplication.getInstance().showToast(title);
    }

    @Subscriber(tag = AppConfig.EVENT_BUS_TAG)
    private void testWithTag(String title) {
        BaseApplication.getInstance().showToast("tag:" + title);
    }

    @Subscriber(tag = AppConfig.EVENT_BUS_TAG, mode = ThreadMode.POST)
    private void testPostWithTag(String title) {
        BaseApplication.getInstance().showToast("tag:POST" + title);
    }

    @Subscriber(mode = ThreadMode.ASYNC)
    private void testWithAsync(String title) {
        BaseApplication.getInstance().showToast("ASYNC" + title);
    }

    @Subscriber(tag = AppConfig.ASYNC_TAG, mode = ThreadMode.ASYNC)
    private void testWithTagAsync(String title) {
        BaseApplication.getInstance().showToast("tag:ASYNC" + title);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        eventBus.unregister(eventBus);
    }
}
